﻿using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace QLab.IO
{
  /// <summary>
  /// Data service for the file system
  /// </summary>
  public class FileSystemDataService
  {
    /// <summary>
    /// Gets the list of files 
    /// </summary>
    /// <param name="directory">The Directory to get the files from</param>
    /// <returns>Returns the List of File info for this directory.
    /// Return null if an exception is raised</returns>
    public static IList<FileInfo> GetFiles(string directory, string searchPattern)
    {
      try
      {
        return (from x in Directory.GetFiles(directory, searchPattern)
                select new FileInfo(x)).ToList();
      }
      catch { }

      return null;
    }


    /// <summary>
    /// Gets the list of directories 
    /// </summary>
    /// <param name="directory">The Directory to get the files from</param>
    /// <returns>Returns the List of directories info for this directory.
    /// Return null if an exception is raised</returns>
    public static IList<DirectoryInfo> GetDirectories(string directory)
    {
      try
      {
        return (from x in Directory.GetDirectories(directory)
                select new DirectoryInfo(x)).ToList();
      }
      catch { }

      return null;
    }

  }
}
